<template>
  <a-card>
    <div>
      <a-button type="primary" @click="createMaterialdetail" icon="add" style="margin-bottom:20px"
        >生成物料详情</a-button
      >
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
      >
      </a-table>
    </div>
  </a-card>
</template>

<script>
import { getAction } from '@api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mixinDevice } from '@/utils/mixin'

export default {
  name: 'HfBomCreate',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  data() {
    return {
      description: 'BOM关联生成',
      productmissionid: '',
      // 表头
      columns: [
        {
          title: '物料代码',
          align: 'center',
          dataIndex: 'materialCode'
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName'
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'sap'
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit'
        },
        {
          title: '标准用量',
          align: 'center',
          dataIndex: 'standard_dosage'
        },
        {
          title: '损耗率',
          align: 'center',
          dataIndex: 'attrition_rate'
        },
        {
          title: '计划用量',
          align: 'center',
          dataIndex: 'plan_dosage'
        },
        {
          title: '发料仓库',
          align: 'center',
          dataIndex: 'warehouse_name'
        },
        {
          title: '实际用量',
          align: 'center',
          dataIndex: 'dosage'
        }
      ],
      url: {
        list: '/production/hfProductmission/materialDetail',
        createMaterialdetail: '/production/hfProductmission/generateproductmissionmaterialdetail'
      },

      dictOptions: {}
    }
  },
  created() {},
  computed: {},
  methods: {
    openList(record) {
      this.queryParam.id = record.id
      this.productmissionid = record.id
      console.log('productmissionId:' + this.productmissionid)
      this.loadBomData()
    },
    createMaterialdetail() {
      getAction(this.url.createMaterialdetail, { id: this.productmissionid }).then(res => {
        // debugger;
        if (res.success) {
          this.$message.success(res.message)
          HfProductmissionMaterialdetailList.methods.loadData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    loadBomData() {
      this.ipagination.current = 1
      let params = this.getQueryParams() //查询条件
      this.loading = true
      getAction(this.url.list, params)
        .then(res => {
          console.log('list:' + this.url.list)
          if (res.success) {
            this.dataSource = res.result.records || res.result
            console.log('datasource:' + res.result.records)
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    }
  }
}
</script>

<style scoped></style>
